package cn.terminus.biz.customer.custompurposeroom;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.custompurposeroom.dto.*;
import cn.terminus.data.customer.custompurposeroom.dao.CustomPurposeRoomDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (CustomPurposeRoom)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:18:58
 */
@Component
public class CustomPurposeRoomManager extends AbstractTerminusManager {
    @Autowired
    private CustomPurposeRoomDao customPurposeRoomDao;

    public Integer add(CustomPurposeRoomNewDto dto) throws DataAccessException {
        try {
            return customPurposeRoomDao.add(dto);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(CustomPurposeRoomEditDto dto) throws DataAccessException {
        try {
            return customPurposeRoomDao.update(dto);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomPurposeRoomResultDto> gets(CustomPurposeRoomGetsDto dto) throws DataAccessException {
        try {
            return customPurposeRoomDao.gets(dto);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomPurposeRoomResultDto> query(CustomPurposeRoomQueryDto dto) throws DataAccessException {
        try {
            return customPurposeRoomDao.query(dto);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(CustomPurposeRoomDeleteDto dto) throws DataAccessException {
        try {
            return customPurposeRoomDao.delete(dto);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<CustomPurposeRoomResultDto> page(CustomPurposeRoomQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<CustomPurposeRoomResultDto> result = (Page<CustomPurposeRoomResultDto>) customPurposeRoomDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), CustomPurposeRoomResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer addMulti(List<CustomPurposeRoomNewDto> customPurposeRoomNewDtoList) throws DataAccessException {
        try {
            return customPurposeRoomDao.addMulti(customPurposeRoomNewDtoList);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }


    public List<CustomPurposeRoomResultDto> queryByContractIdsAndType(CustomRoomInfoGetDto roomInfoGetDto) throws DataAccessException {
        try {
            return customPurposeRoomDao.queryByContractIdsAndType(roomInfoGetDto);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteByContractIds(List<Long> contractIds) throws DataAccessException {
        try {
            return customPurposeRoomDao.deleteByContractIds(contractIds);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer countContractRooms(List<Long> roomIds) throws DataAccessException {
        try {
            return customPurposeRoomDao.countContractRooms(roomIds);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteByCustomerId(CustomPurposeRoomDeleteDto dto) throws DataAccessException{
        try {
            return customPurposeRoomDao.deleteByCustomerId(dto);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
